<template>
  <div class="head-container">
    <el-input
      v-model="queryParams.appName"
      placeholder="请输入站点名称"
      clearable
      @keyup.enter="handleQuery"
      class="mb-20px"
    >
      <template #prefix>
        <Icon icon="ep:search" />
      </template>
    </el-input>
  </div>
  <div class="head-container">
    <el-table
      v-loading="loading"
      :data="list"
      :stripe="true"
      :show-overflow-tooltip="true"
      @row-click="handleRowClick"
      highlight-current-row
    >
      <el-table-column label="类型" align="center" prop="terminalType">
        <template #default="scope">
          <dict-tag :type="DICT_TYPE.TERMINAL" :value="scope.row.terminalType" />
        </template>
      </el-table-column>
      <el-table-column label="名称" align="center" prop="appName" />
    </el-table>
  </div>
</template>

<script setup lang="ts">
import { DICT_TYPE } from '@/utils/dict'
import { AppSiteApi, AppSiteVO } from '@/api/cms/appsite'

/** 站点 列表 */
defineOptions({ name: 'AppSiteSimpleList' })

const loading = ref(true) // 列表的加载中
const list = ref<AppSiteVO[]>([]) // 列表的数据
const total = ref(0) // 列表的总页数
const queryParams = reactive({
  pageNo: 1,
  pageSize: -1,
  appName: undefined
})
/** 处理某一行的点击 */
const handleRowClick = (row: AppSiteVO) => {
  emits('row-click', row)
}
const emits = defineEmits(['row-click'])
/** 查询列表 */
const getList = async () => {
  loading.value = true
  try {
    const data = await AppSiteApi.getAppSitePage(queryParams)
    list.value = data.list
    total.value = data.total
  } finally {
    loading.value = false
  }
}

/** 搜索按钮操作 */
const handleQuery = () => {
  getList()
}

/** 初始化 **/
onMounted(() => {
  getList()
})
</script>
